﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Manage_HosptialList : System.Web.UI.Page, HZ.MBSM.BLL.IPageDescribe
{
    public string strConditions;

    protected void Page_Load(object sender, EventArgs e)
    {
        int i = 0;
        if (HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
        {
            if (!IsPostBack)
            {
                //08.11 增加了try{}catch{}     


                Db DbProject = new Db();
                string strSql = "select * from area where areaid in (select areaid from hospital) ";
                System.Data.IDataReader dr = DbProject.DataReader(strSql);
                //lstAreaId.DataSource = dr;
                //lstAreaId.DataTextField = "areaname";
                //lstAreaId.DataValueField = "areaid";
                // lstAreaId.Items.Add("全部");
                lstAreaId.Items.Clear();
                while (dr.Read())
                {
                    string areaname = dr["areaname"].ToString();
                    string areaid = dr["areaid"].ToString();
                    lstAreaId.Items.Add(new ListItem(areaname, areaid));
                    //lstAreaId.Items.Add(dr["areaname"].ToString());
                    //lstAreaId.Items[++i].Value = dr["areaid"].ToString();

                }
                //08.11
                // if (lstAreaId.Items.Count > 0)
                // {
                lstAreaId.Items.Add(new ListItem("--全部--", "0"));
                lstAreaId.SelectedIndex = lstAreaId.Items.Count - 1;
                // }

                lstAreaId.DataBind();
                dr.Close();
                dr.Dispose();
                DbProject.Close();
                lstDistinction.Items.Add("全部");
                lstDistinction.Items.Add("三甲");
                lstDistinction.Items.Add("三乙");
                lstDistinction.Items.Add("二甲");
                lstDistinction.Items.Add("二乙");
                lstDistinction.Items.Add("一甲");
                lstDistinction.Items.Add("一乙");
            }

            showGridView();
        }

    }
    protected void Button5_Click(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// 数据绑定
    /// </summary>
    public void showGridView()
    {
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "hospital left join area on hospital.areaid=area.areaid";                                               //要查询的表明
        dbPage.Key = "accountid";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "area.areaname,accountid,HospitalName,UserCode, case distinction when '0' then '三甲' when '1' then '三乙' when '2' then '二甲' when '3' then '二乙' when '4' then '一甲' when '5' then '一乙'end as distinction, case sort when '0' then '综合' when '1' then '专科' when '2' then '中医' end as sort";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 10;                                                    //没有显示记录条数   
        dbPage.OrderBy = "HospitalName,UserCode";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        dtlHospital.DataSource = dr;
        dtlHospital.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键




    }
    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        //08.11  下面几个语句加了tirm（）
        string strtemp = "", HospitalName = "", _UserCode, _AreaId, _Distinction;
        HospitalName = txtHospitalName.Text.ToString().Trim();
        _UserCode = txtUserCode.Text.ToString().Trim();
        _AreaId = lstAreaId.SelectedValue.Trim();
        _Distinction = lstDistinction.Text.Trim();
        switch (_Distinction)
        {
            case "全部":
                _Distinction = "全部";
                break;
            case "三甲":
                _Distinction = "0";
                break;
            case "三乙":
                _Distinction = "1";
                break;
            case "二甲":
                _Distinction = "2";
                break;
            case "二乙":
                _Distinction = "3";
                break;
            case "一甲":
                _Distinction = "4";
                break;
            case "一乙":
                _Distinction = "5";
                break;
        }
        if (_Distinction != "全部")
        {
            strtemp = strtemp + " Distinction =" + _Distinction + " and";
        }
        if (_AreaId != "0")
        {
            strtemp = strtemp + " Hospital.areaid =" + _AreaId + " and";
        }
        if (_UserCode != "")
        {
            strtemp = strtemp + " UserCode like '%" + _UserCode + "%' and";
        }
        if (HospitalName != "")
        {
            strtemp = strtemp + " HospitalName like '%" + HospitalName + "%' and";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;
    }
    #region IPageDescribe 成员

    public string Name
    {
        get { return "医院管理"; }
    }

    public string Describe
    {
        get { return "医院管理"; }
    }

    public string ParentName
    {
        get { return "用户管理"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
            return _AccountType;
        }
    }

    #endregion
}
